package com.hyk.learning.test.server;

import com.hyk.learning.annotation.RpcScan;
import com.hyk.learning.config.RpcServiceConfig;
import com.hyk.learning.remoting.transport.netty.server.NettyRpcServer;
import com.hyk.learning.test.helloApi.HelloService;
import com.hyk.learning.test.server.com.hyk.learning.serviceimpl.HelloServiceImpl2;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.net.UnknownHostException;

/**
 * @className: NettyServerMain
 * @author: hyk199710
 * @description: Server: Automatic registration service via @RpcService annotation
 * @date: 2024/5/25 17:16
 */
@RpcScan(basePackage = {"com.hyk.learning"})
public class NettyServerMain {

    public static void main(String[] args) throws UnknownHostException {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(NettyServerMain.class);
        NettyRpcServer nettyRpcServer = (NettyRpcServer) applicationContext.getBean("nettyRpcServer");
        HelloService helloService2 = new HelloServiceImpl2();
        RpcServiceConfig rpcServiceConfig = RpcServiceConfig.builder()
                .group("test2").version("version2").service(helloService2)
                .build();
        nettyRpcServer.registerService(rpcServiceConfig);
        nettyRpcServer.start();
    }

}
